/**
 * 
 */
package com.sofast.dao;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import com.mysql.jdbc.StringUtils;
import com.sofast.bean.AlbumBean;
import com.sofast.bean.SongerBean;
import com.sofast.common.DBConfig;

/**
 * @author alex
 *
 */
public class AlbumDao {
	
	public Connection conn;
	
	public AlbumDao() {
		conn = DBConfig.getConn();
	}
	
	public long insert(AlbumBean album) {
		long id = -1;
		try {
			String sql = "INSERT INTO album(name,hot,summary,songer_id,publishtime,company) values ('"+album.getName()+"',"+
				album.getHot()+",'"+album.getSummary()+"',"+album.getSonger().getId()+","+album.getPublishTime()+",'"+album.getComp()+"')";
			PreparedStatement sta = conn.prepareStatement(sql, new String[]{"id"});
			DatabaseMetaData dmd = conn.getMetaData();
			sta.executeUpdate();
			if(dmd.supportsGetGeneratedKeys()) {
				ResultSet res = sta.getGeneratedKeys();
				if(res.next()) {
					id = res.getLong(1);
				}
				res.close();
			}
			sta.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		return id;
	} 
	
	public static void main(String[] args) {
	}
}
